package com.fsl.springcloudstream.schedule;

import com.fasterxml.jackson.databind.annotation.JsonAppend;
import com.fsl.springcloudstream.messaging.SinkClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.util.Date;

/**
 * @author dell
 * 定时任务
 */
@Component
public class MessageScheduled {

    @Autowired
    private SinkClient sinkClient;


    @Scheduled(cron = "0/5 * * * * ?")
    public void send(){
        String msg = "hello world!";
        sinkClient.output().send(MessageBuilder.withPayload(msg).build());
        System.out.println("----------------------发送消息成功------------------" + getInstance().format(new Date()));
    }

    /**
     * 获取日期格式化对象
     * @return
     */
    private static DateFormat getInstance(){
        return DateFormat.getDateTimeInstance();
    }
}
